import service from '@/utils/requestTopo';

// 查询虚拟机列表
export const getVM = params =>
  service({
    url: '/simulation/res/instance/qemu/',
    method: 'get',
    params,
  });

export const addVM = data =>
  service({
    url: '/simulation/res/instance/qemu/',
    method: 'post',
    data,
  });

export const delVM = id =>
  service({
    url: `/simulation/res/instance/qemu/${id}/`,
    method: 'delete',
  });

export const getVMDetailApi = id =>
  service({
    url: `/simulation/res/instance/qemu/${id}/`,
    method: 'get',
  });
export const editorVM = (id, data) =>
  service({
    url: `/simulation/res/instance/qemu/${id}/`,
    method: 'put',
    data,
  });

// 操作虚拟机,开关
export const operationVM = (id, data) =>
  service({
    url: `/simulation/res/instance/qemu/${id}/`,
    method: 'post',
    data,
  });

// 操作虚拟机,开关
export const updateVMPassword = (id, data) =>
  service({
    url: `/simulation/res/instance/qemu/${id}/password/`,
    method: 'put',
    data,
  });

// 网卡列表
export const getNetWorkList = id =>
  service({
    url: `/simulation/res/instance/qemu/${id}/network/`,
    method: 'get',
  });

// 删除网卡
export const delNetWork = (vmID, uuid) =>
  service({
    url: `/simulation/res/instance/qemu/${vmID}/network/${uuid}/`,
    method: 'delete',
  });

// 新建网卡
export const addVMNetWork = (vmID, data) =>
  service({
    url: `/simulation/res/instance/qemu/${vmID}/network/`,
    method: 'post',
    data,
  });

// 编辑网卡
export const editorVMNetWork = (vmID, data) =>
  service({
    url: `/simulation/res/instance/qemu/${vmID}/network/`,
    method: 'put',
    data,
  });

// 转换qemu
export const convertQemuImg = (id, data) =>
  service({
    url: `/simulation/res/instance/qemu/${id}/convert/`,
    method: 'post',
    data,
  });

// 发送文件
export const sendFileQemu = (id, data) =>
  service({
    url: `/simulation/res/instance/qemu/${id}/file/`,
    method: 'post',
    data,
  });

// 发送文件-最新的
export const sendFileQemuNew = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${ id }/file/`,
        method: 'post',
        data,
    });

/**
 * 获取快照列表
 * @param id
 * @returns {*}
 */
export const getSnapshotList = id =>
    service({
        url: `/simulation/res/instance/qemu/${id}/snapshot/`,
        method: 'get',
    });

/**
 * 删除快照
 * @param qemuID
 * @param snapshotID
 * @returns {*}
 */
export const delSnapshotApi = (qemuID, snapshotID) =>
    service({
        url: `/simulation/res/instance/qemu/${qemuID}/snapshot/${snapshotID}/delete/`,
        method: 'delete',
    });


/**
 * 新建快照
 * @param id
 * @param data
 * @returns {*}
 */
export const addSnapshotApi = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/snapshot/`,
        method: 'post',
        data,
    });


/**
 * 回滚快照
 * @param qemuID
 * @param snapshotID
 * @returns {*}
 */
export const revertSnapshotApi = (qemuID, snapshotID) =>
    service({
        url: `/simulation/res/instance/qemu/${qemuID}/snapshot/${snapshotID}/revert/`,
        method: 'post',
    });


/**
 * 获取场景快照列表
 * @param id
 * @returns {*}
 */
export const getSnapshotSceneList = id =>
    service({
        url: `/simulation/scene/scene/${id}/snapshot/`,
        method: 'get',
    });

/**
 * 删除场景快照
 * @param id
 * @param snapshotID
 * @returns {*}
 */
export const delSnapshotSceneApi = (id, snapshotID) =>
    service({
        url: `/simulation/scene/scene/${id}/snapshot/${snapshotID}/delete/`,
        method: 'delete',
    });


/**
 * 新建场景快照
 * @param id
 * @param data
 * @returns {*}
 */
export const addSnapshotSceneApi = (id, data) =>
    service({
        url: `/simulation/scene/scene/${id}/snapshot/`,
        method: 'post',
        data,
    });


/**
 * 回滚场景快照
 * @param id
 * @param snapshotID
 * @returns {*}
 */
export const revertSnapshotSceneApi = (id, snapshotID) =>
    service({
        url: `/simulation/scene/scene/${id}/snapshot/${snapshotID}/revert/`,
        method: 'post',
    });


/**
 * 获取虚拟机所有一二级节点
 * @returns {*}
 */
export const getVmNodeAllApi = () =>
    service({
        url: `/simulation/res/computer/tree/`,
        method: 'get'
    });

/**
 * 获取计算节点下虚拟机（树）
 * @returns {*}
 */
export const getVmNodeToVmApi = (id, params) =>
    service({
        url: `/simulation/res/computer/${id}/qemu/`,
        method: 'get',
        params
    });

/**
 * 获取树下节点（包含展开懒加载、搜索筛选、滚动加载）
 * @param params
 * @returns {*}
 */
export const getVmNodeTreeApi = (params) =>
    service({
        url: `/simulation/res/instance/qemu/tree/`,
        method: 'get',
        params
    });

/**
 * 搜索
 * @returns {*}
 */
export const getVmNodeToVmSearchApi = (params) =>
    service({
        url: `/simulation/res/instance/qemu/tree/`,
        method: 'get',
        params
    });

/**
 * 查询集群-虚拟机列表
 * @param id
 * @param params
 * @returns {*}
 */
export const getVMListByClusterApi = (id, params) =>
    service({
        url: `/simulation/res/cluster/${id}/qemuList/`,
        method: 'get',
        params,
    });


/**
 * 查询计算节点-虚拟机列表
 * @param id
 * @param params
 * @returns {*}
 */
export const getVMListByComputedApi = (id, params) =>
    service({
        url: `/simulation/res/computer/${id}/qemuList/`,
        method: 'get',
        params,
    });

/**
 * 新增虚拟机
 * @param data
 * @returns {*}
 */
export const addVMNewApi = data =>
    service({
        url: '/simulation/res/instance/qemu/',
        method: 'post',
        data,
    });

/**
 * 获取虚拟机下概览
 * @param id
 * @returns {*}
 */
export const getVmToOverViewsApi = (id) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/outline/`,
        method: 'get'
    });

/**
 * 获取虚拟机下硬件
 * @param id
 * @returns {*}
 */
export const getVmToHardwareApi = (id) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/hardware/`,
        method: 'get'
    });


/**
 * 编辑虚拟机基本信息（虚拟机名称、硬见基本信息： CPU、内存）
 * @param id
 * @param data
 * @returns {*}
 */
export const editorVmHardWareBaseApi = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/`,
        method: 'put',
        data,
    });

/**
 * 添加硬件
 * @param id
 * @param data
 * @returns {*}
 */
export const addHardWareApi = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/hardware/`,
        method: 'post',
        data
    });

/**
 * 删除硬盘
 * @param id
 * @param hdId
 * @param data
 * @returns {*}
 */
export const delHardWareApi = (id, hdId, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/hardware/${hdId}/`,
        method: 'delete',
        data
    });

/**
 * 探针状态查询
 * @param id
 * @returns {*}
 */
export const probeStatusSearchApi = (id) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/agent/`,
        method: 'get'
    });

/**
 * 虚拟机管理-拓展功能-命令执行
 * @param id
 * @param data
 * @returns {*}
 */
export const commandExecShellApi = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/command/`,
        method: 'post',
        data
    });


/**
 * 命令执行返回结果
 * @param taskID
 * @returns {*}
 */
export const commandExecShellContainerApi = (taskID) =>
    service({
        url: `/simulation/res/instance/qemu/task/${taskID}/command/`,
        method: 'get'
    });

/**
 * 批量操作
 * @param data
 * @returns {*}
 */
export const batchOptionByVmApi = (data) =>
    service({
        url: `/simulation/res/instance/qemu/batch/`,
        method: 'post',
        data
    });


/**
 * 新建网卡
 * @param id
 * @param data
 * @returns {*}
 */
export const addVMNetWorkApi = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/network/`,
        method: 'post',
        data,
    });

/**
 * 销毁虚拟机
 * @param id
 * @param data
 * @returns {*}
 */
export const destroyVMApi = (id, data) =>
    service({
        url: `/simulation/res/instance/qemu/${id}/destroy/`,
        method: 'post',
        data,
    });

/**
 * 读取public下PDF
 * @returns {*}
 */
export const getPublicPDF = () =>
    service({
        url: `/simulation/scene/scene/chart/`,
        method: 'get'
    });
